<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <xsl:apply-templates select="//CoverageDSPriv" />
  </xsl:template>

  <xsl:template match="CoverageDSPriv">
    <script>
      function toggleDiv( imgId, divId )
      {
      eDiv = document.getElementById( divId );
      eImg = document.getElementById( imgId );

      if ( eDiv.style.display == "none" )
      {
      eDiv.style.display = "block";
      eImg.src = "images/arrow_minus_small.gif";
      }
      else
      {
      eDiv.style.display = "none";
      eImg.src = "images/arrow_plus_small.gif";
      }
      }
    </script>
    <h1>
      Coverage Report:
    </h1>
    <h2>Total Coverage</h2>
    <table border="1" cellSpacing="0" cellPadding="5" >
      <xsl:variable name="covered.lines" select="sum(//CoverageDSPriv/Module/LinesCovered)" />
      <xsl:variable name="uncovered.lines" select="sum(//CoverageDSPriv/Module/LinesNotCovered)" />
      <xsl:variable name="covered.blocks" select="sum(//CoverageDSPriv/Module/BlocksCovered)" />
      <xsl:variable name="uncovered.blocks" select="sum(//CoverageDSPriv/Module/BlocksNotCovered)" />

      <thead style="text-align: center;">
        <td style="background-color: forestGreen; color:white">Covered (%Line)</td>
        <td style="background-color: fireBrick; color: white;">Uncovered (%Lines)</td>
        <td style="background-color: forestGreen; color:white;">Covered (%Blocks)</td>
        <td style="background-color: fireBrick; color: white;">Uncovered (%Blocks)</td>
      </thead>
      <tr style="text-align: center;">
        <td>
          <xsl:value-of select="round($covered.lines div ($uncovered.lines + $covered.lines) * 10000) div 100" />
        </td>
        <td>
          <xsl:value-of select="round($uncovered.lines div ($uncovered.lines + $covered.lines) * 10000) div 100" />
        </td>
        <td>
          <xsl:value-of select="round($covered.blocks div ($uncovered.blocks + $covered.blocks) * 10000) div 100" />
        </td>
        <td>
          <xsl:value-of select="round($uncovered.blocks div ($uncovered.blocks + $covered.blocks) * 10000) div 100" />
        </td>
      </tr>
    </table>
    <h2>Modules:</h2>
    <xsl:apply-templates select="Module" />

  </xsl:template>


  <xsl:template match="//CoverageDSPriv/SourceFileNames">
  </xsl:template>

  <xsl:template match="//CoverageDSPriv/Module">
    <xsl:variable name="module.id" select="generate-id()" />
    <xsl:variable name="covered.lines" select="LinesCovered" />
    <xsl:variable name="uncovered.lines" select="LinesNotCovered" />
    <xsl:variable name="covered.blocks" select="BlocksCovered" />
    <xsl:variable name="uncovered.blocks" select="BlocksNotCovered" />
    <xsl:variable name="Module.Name" select="ModuleName" />

    <table border="0" cellSpacing="0" cellPadding="5" >
      <tr style="text-align: center;">
        <td style="text-align: left;">
          <xsl:value-of select="ModuleName" />
        </td>
        <td>
          <input type="image" src="images/arrow_plus_small.gif">
            <xsl:attribute name="id">img<xsl:value-of select="$module.id"/>
            </xsl:attribute>
            <xsl:attribute name="onclick">javascript:toggleDiv('img<xsl:value-of select="$module.id"/>', 'divDetails<xsl:value-of select="$module.id"/>');
            </xsl:attribute>
          </input>
        </td>
      </tr>
    </table>
    <div style="display:none">
      <xsl:attribute name="id">
        divDetails<xsl:value-of select="$module.id"/>
      </xsl:attribute>
      <blockquote>
        <table border="1" cellSpacing="0" cellPadding="5" >
          <thead style="text-align: center;">
            <td>Class</td>
            <td style="background-color: forestGreen; color:white">Covered (Lines)</td>
            <td style="background-color: fireBrick; color: white;">Uncovered (Lines)</td>
            <td style="background-color: darkblue; color: white;">Total Coverage (%Lines)</td>
            <td style="background-color: forestGreen; color:white;">Covered (Blocks)</td>
            <td style="background-color: fireBrick; color: white;">Uncovered (Blocks)</td>
            <td style="background-color: darkblue; color: white;">Total Coverage (%Blocks)</td>
          </thead>
          <xsl:apply-templates select="NamespaceTable/Class" >
            <xsl:sort select="LinesCovered div (LinesNotCovered + LinesCovered)" order="ascending" data-type="number"/>
          </xsl:apply-templates>
        </table>
        <h2> </h2>
      </blockquote>
    </div>
  </xsl:template>

  <xsl:template match="NamespaceTable/Class">

    <xsl:variable name="covered.lines" select="LinesCovered" />
    <xsl:variable name="uncovered.lines" select="LinesNotCovered" />
    <xsl:variable name="covered.blocks" select="BlocksCovered" />
    <xsl:variable name="uncovered.blocks" select="BlocksNotCovered" />
    <xsl:variable name="Class.Name" select="ClassName" />
    <tr style="text-align: center;">
      <td style="text-align: left;">
        <xsl:value-of select="$Class.Name" />
      </td>
      <td>
        <xsl:value-of select="$covered.lines" />
      </td>
      <td>
        <xsl:value-of select="$uncovered.lines" />
      </td>
      <td>
        <xsl:value-of select="round($covered.lines div ($uncovered.lines+ $covered.lines) * 10000) div 100" />
      </td>
      <td>
        <xsl:value-of select="$covered.blocks" />
      </td>
      <td>
        <xsl:value-of select="$uncovered.blocks" />
      </td>
      <td>
        <xsl:value-of select="round($covered.blocks div ($uncovered.blocks+ $covered.blocks) * 10000) div 100" />
      </td>
    </tr>

  </xsl:template>

</xsl:stylesheet>
